package com.rong.creatmodel.buildermodel.rk_test;

import java.util.ArrayList;
import java.util.List;

public class BuilderModel {

    public static void main(String[] args) {
        Directory directory = new Directory();
        Builder b1 = new BuilderA();
        directory.construct(b1);
        Producr p1 = b1.getResult();
        p1.show();

        BuilderB b = new BuilderB();
        directory.construct(b);
        Producr p2 = b.getResult();
        p2.show();
    }
}


// 服务员 使用相应的生成器创建对应的产品
class Directory{

    public void construct(Builder builder){
        builder.builderParts();
    }

}
//生成器
abstract class Builder{
    // 生成产品
    public abstract void builderParts();

    // 获取产品
    public abstract Producr getResult();
}

// 具体的生成器生成具体的套餐A
class BuilderA extends Builder{
    Producr pA = new Producr();
    @Override
    public void builderParts() {
        pA.add("A");
        pA.add("B");
        pA.add("c");
        pA.add("d");

    }

    @Override
    public Producr getResult() {
        return pA;
    }
}

// 具体套餐B
class BuilderB extends Builder{
    Producr pB = new Producr();

    @Override
    public void builderParts() {
        pB.add("A");
        pB.add("D");
    }

    @Override
    public Producr getResult() {
        return pB;
    }
}

class Producr{
    List<String> parts = new ArrayList<>();

    public void add(String part){
        parts.add(part);
    }

    public void show(){
        System.out.println("产品组成：");
        for(String part:parts){
            System.out.println(part + " ");
            System.out.println("\n");
        }
    }
}
